package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebOrderController;
import com.web.controller.web.WebSysLogController;
import com.web.entity.OrderRecordForPlatform;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface OrderRecordForPlatformMapper {
    @Delete({
        "delete from t_order_record_for_platform",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_order_record_for_platform (order_num, consumer,",
        " merchant, store, ",
        " consumer_phone, merchant_phone, ",
        " store_id, consume_bal, ",
        " tip_bal, total_bal, ",
        " transfer_profit, transfer_bal, ",
        " merchant_income, create_time, ",
        " modify_time)",
        " values (#{orderNum,jdbcType=VARCHAR}, #{consumer,jdbcType=VARCHAR}, ",
        " #{merchant,jdbcType=VARCHAR}, #{store,jdbcType=VARCHAR}, ",
        " #{consumerPhone,jdbcType=VARCHAR}, #{merchantPhone,jdbcType=VARCHAR}, ",
        " #{storeId,jdbcType=BIGINT}, #{consumeBal,jdbcType=DECIMAL}, ",
        " #{tipBal,jdbcType=DECIMAL}, #{totalBal,jdbcType=DECIMAL}, ",
        " #{transferProfit,jdbcType=DECIMAL}, #{transferBal,jdbcType=DECIMAL}, ",
        " #{merchantIncome,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP}, ",
        " #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(OrderRecordForPlatform record);

    @InsertProvider(type=OrderRecordForPlatformSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(OrderRecordForPlatform record);

    @Select({
        "select",
        " id, order_num, consumer, merchant, store, consumer_phone, merchant_phone, store_id, ",
        " consume_bal, tip_bal, total_bal, transfer_profit, transfer_bal, merchant_income, ",
        " create_time, modify_time",
        " from t_order_record_for_platform",
        " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="order_num", property="orderNum", jdbcType=JdbcType.VARCHAR),
        @Result(column="consumer", property="consumer", jdbcType=JdbcType.VARCHAR),
        @Result(column="merchant", property="merchant", jdbcType=JdbcType.VARCHAR),
        @Result(column="store", property="store", jdbcType=JdbcType.VARCHAR),
        @Result(column="consumer_phone", property="consumerPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="merchant_phone", property="merchantPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="store_id", property="storeId", jdbcType=JdbcType.BIGINT),
        @Result(column="consume_bal", property="consumeBal", jdbcType=JdbcType.DECIMAL),
        @Result(column="tip_bal", property="tipBal", jdbcType=JdbcType.DECIMAL),
        @Result(column="total_bal", property="totalBal", jdbcType=JdbcType.DECIMAL),
        @Result(column="transfer_profit", property="transferProfit", jdbcType=JdbcType.DECIMAL),
        @Result(column="transfer_bal", property="transferBal", jdbcType=JdbcType.DECIMAL),
        @Result(column="merchant_income", property="merchantIncome", jdbcType=JdbcType.DECIMAL),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    OrderRecordForPlatform selectByPrimaryKey(Long id);

    @UpdateProvider(type=OrderRecordForPlatformSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderRecordForPlatform record);

    @Update({
        "update t_order_record_for_platform",
        " set order_num = #{orderNum,jdbcType=VARCHAR},",
          " consumer = #{consumer,jdbcType=VARCHAR},",
          " merchant = #{merchant,jdbcType=VARCHAR},",
          " store = #{store,jdbcType=VARCHAR},",
          " consumer_phone = #{consumerPhone,jdbcType=VARCHAR},",
          " merchant_phone = #{merchantPhone,jdbcType=VARCHAR},",
          " store_id = #{storeId,jdbcType=BIGINT},",
          " consume_bal = #{consumeBal,jdbcType=DECIMAL},",
          " tip_bal = #{tipBal,jdbcType=DECIMAL},",
          " total_bal = #{totalBal,jdbcType=DECIMAL},",
          " transfer_profit = #{transferProfit,jdbcType=DECIMAL},",
          " transfer_bal = #{transferBal,jdbcType=DECIMAL},",
          " merchant_income = #{merchantIncome,jdbcType=DECIMAL},",
          " create_time = #{createTime,jdbcType=TIMESTAMP},",
          " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(OrderRecordForPlatform record);

    @SelectProvider(type = OrderRecordForPlatformSqlProvider.class, method = "selectAllOrderLogs")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="order_num", property="orderNum", jdbcType=JdbcType.VARCHAR),
            @Result(column="consumer", property="consumer", jdbcType=JdbcType.VARCHAR),
            @Result(column="merchant", property="merchant", jdbcType=JdbcType.VARCHAR),
            @Result(column="store", property="store", jdbcType=JdbcType.VARCHAR),
            @Result(column="consumer_phone", property="consumerPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="merchant_phone", property="merchantPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="store_id", property="storeId", jdbcType=JdbcType.BIGINT),
            @Result(column="consume_bal", property="consumeBal", jdbcType=JdbcType.DECIMAL),
            @Result(column="tip_bal", property="tipBal", jdbcType=JdbcType.DECIMAL),
            @Result(column="total_bal", property="totalBal", jdbcType=JdbcType.DECIMAL),
            @Result(column="transfer_profit", property="transferProfit", jdbcType=JdbcType.DECIMAL),
            @Result(column="transfer_bal", property="transferBal", jdbcType=JdbcType.DECIMAL),
            @Result(column="merchant_income", property="merchantIncome", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Page<OrderRecordForPlatform> selectAllOrderLogs(WebSysLogController.OrderLogColumns orderLogColumns);

    @Select({
            "SELECT sum(merchant_income+transfer_bal) from t_order_record_for_platform where store_id=#{id,jdbcType=BIGINT}"
    })
    Double countTotalBal(Long id);

    @Select({
            "SELECT sum(transfer_bal) from t_order_record_for_platform where store_id=#{id,jdbcType=BIGINT}"
    })
    Double countTransfer(Long id);
}